package com.sad.dao.impl;

import java.io.IOException;
import java.util.Map;

import org.apache.http.client.methods.RequestBuilder;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;

import com.sad.dao.BaseRecord;
import com.sad.model.JsonObject;
import com.sad.model.Orderback;
import com.sad.util.G;

public class ExpressformRecord extends BaseRecord<Orderback> {

	@Override
	protected String getUrl(Map<String, Object> parms) {
		String orderid = (String) parms.get("orderid");
		String url = G.system.url + "/toy/order/detail?orderid=" + orderid;

		return url;
	}

	@Override
	protected JsonObject<Orderback> parserJsonObject(String json) throws JsonParseException,
			JsonMappingException, IOException {
		ObjectMapper mapper = new ObjectMapper();
		return mapper.readValue(json, new TypeReference<JsonObject<Orderback>>() {
		});
	}
	
	@Override
	protected String postUrl(Map<String, Object> parms) {
		return G.system.url + "/toy/express/create";
	}

	/* (non-Javadoc)
	 * @see com.sad.dao.BaseRecord#setNameValuePair(java.util.List)
	 */
	@Override
	protected RequestBuilder builderParameter(RequestBuilder builder,Map<String, Object> parms) {
		String orderid = (String)parms.get("orderid");
		String excode = (String)parms.get("excode");
		String userid = (String)parms.get("userid");
		String company = (String)parms.get("company");
		String courier = (String)parms.get("courier");
		String exmobile = (String)parms.get("exmobile");
		
		
		builder.addParameter("orderid", orderid);
		builder.addParameter("excode", excode);
		builder.addParameter("userid", userid);
		builder.addParameter("company", company);
		builder.addParameter("courier", courier);
		builder.addParameter("exmobile", exmobile);
		
		return builder;
	}
	
	

}
